package com.lz.demo1;

/**
 * @ClassName Score
 * @Description 百分制分数
 * @Author 2214361854
 * @Date 2022/5/28 14:08
 * @Version 1.0
 */
public class Score {
    int score;
    char level;

    public Score(int score) {
        this.score = score;
        //计算五档分数，保存到成员变量level
        this.level = setLevel(score);
    }

    private char setLevel(int s) {
        char r = 0;
        switch (s / 10) {
            case 10:
            case 9:
                r = 'A';
                break;
            case 8:
            case 7:
                r = 'B';
                break;
            case 6:
                r = 'C';
                break;
            case 5:
            case 4:
            case 3:
            case 2:
                r = 'D';
                break;
            default:
                r = 'E';
        }
        return r;

    }

    @Override
    public String toString() {
        return "Score{" +
                "score=" + score +
                ", level=" + level +
                '}';
    }
}
